<template>
	<view class="content">
		<view class="top">
			<view class="left">
				<view class="line" :class="[index == 0?'wallet':'', index == typeValue?'select':'']"
					v-for="(item, index) in type" :key="index">
					<span v-if="index == 0">
						<image :src="item.icon"></image>
						<view class="text alpsoftjurnal">{{item.text}}</view>
					</span>
					<span v-else>
						<view class="num">{{item.num}}</view>
						<view class="text alpsoftjurnal">{{item.text}}</view>
					</span>
				</view>
			</view>
			<view class="right" v-if="show_btn == 1">
				<view class="button alpsoftjurnal" @click="jumpPage('/pages/client/pay', 1)">
					{{$t('gold.button1')}}
				</view>
				<view class="button alpsoftjurnal" @click="jumpPage('/pages/client/wallet/withdraw-deposit')">
					{{$t('gold.button2')}}
				</view>
			</view>
		</view>
		<scroll-view class="scroll-view" scroll-y="true" @scrolltolower="lower">
			<view class="item" v-for="(item, index) in list" :key="index">
				<view class="left">
					<view class="title alpsoftjurnal" v-if="lang == 'wwe'">
						{{ item.uyg_from }}
					</view>
					<view class="title" v-else>
						{{ item.from }}
					</view>
					{{ item.create_time}}
				</view>
				<view class="right">
					{{item.type ==1?'+':'-' }} {{ item.quantity }}
					<image src="@/static/gold.png"></image>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import util from '../../../utils/util'
	export default {
		data() {
			return {
				params: {
					page: 1,
					page_size: 10,
				},
				type: [],
				typeValue: 0,
				total: 0,
				list: [],
				lang: '',
				show_btn: ''
			}
		},
		onShow() {
			this.params.page = 1
			this.list = []
			this.coinList()
			this.getUserCoinAmount()
			this.showBtnStatus()
			this.setList()
			util.setNavTitle()
			this.lang = uni.getStorageSync('language')
		},
		methods: {
			showBtnStatus() {
				uni.request({
					url: this.configs.webUrl + '/api/recharge/showBtnStatus',
					success: res => {
						console.log(res);
						this.show_btn = res.data.data.show_btn
					}
				})
			},
			setList() {
				this.type = [{
					text: this.$t('user.wallet'),
					icon: require('@/static/wallet.png')
				}, {
					text: this.$t('user.gold1'),
					num: 0,
				}, {
					text: this.$t('user.gold2'),
					num: 0
				}]
			},
			jumpPage(path, type) {
				if(type == 1) {
					const info = uni.getSystemInfoSync()
					if (info.system.indexOf('Android') > -1) {
						uni.navigateTo({
							url: '/pages/client/vipcard/recharge'
						})
					} else {
						uni.navigateTo({
							url: path
						})
					}
				} else {
					uni.navigateTo({
						url: path
					})
				}
			},
			typeFn(index) {
				this.typeValue = index
			},
			coinList() {
				let userinfo = uni.getStorageSync('userinfo')
				this.params.token = userinfo.token
				uni.request({
					url: this.configs.webUrl + '/api/user_coin/coinList',
					data: this.params,
					success: res => {
						console.log(res);
						this.list = this.list.concat(res.data.data.list)
						this.total = res.data.data.count
					}
				})
			},
			lower() {
				if (this.total > this.params.page * this.params.page_size) {
					this.params.page++
					this.coinList()
				}
			},
			getUserCoinAmount() {
				uni.request({
					url: this.configs.webUrl + '/api/user_coin/getUserCoinAmount',
					data: {
						token: uni.getStorageSync('userinfo').token
					},
					success: res => {
						console.log(res);
						this.type[1].num = res.data.data.forever_coin
						this.type[2].num = res.data.data.coin_amount
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	view {
		font-size: initial;
	}

	.content {
		padding: 20rpx;

		.top {
			border-radius: 24rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			overflow: hidden;
			height: 146rpx;
			margin-bottom: 10rpx;
			background: linear-gradient(90deg, #F75581 0%, #C860FF 100%);

			.left {
				display: flex;
				justify-content: space-between;
				width: calc(100% - 160rpx);
				height: 100%;

				.wallet {
					image {
						width: 96rpx;
						height: 96rpx;
					}
				}

				.line {
					width: 100%;
					padding: 10rpx 20rpx;
					text-align: center;
					.text {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
					}
					.num {
						font-size: 40rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 600;
						color: #FFFFFF;
						margin: 20rpx 0;
					}
				}

				.select {
					background: #fff;

					.text, .num {
						color: #E03A1C;
					}
				}
			}

			.right {
				padding: 0 20rpx;

				.button {
					width: 130rpx;
					height: 48rpx;
					font-size: 24rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #F85A55;
					background: #fff;
					border-radius: 50rpx;
					margin: 10rpx 0;
					line-height: 48rpx;
					text-align: center;
				}
			}
		}

		.scroll-view {
			height: calc(100vh - 40px - 85px);

			.item {
				display: flex;
				padding: 20rpx;
				align-items: center;
				background: #fff;
				border-radius: 24rpx;
				margin: 10rpx 0;
				justify-content: space-between;

				.left {
					.title {
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						color: #000000;
						margin-bottom: 10rpx;
					}

					font-size: 24rpx;
					font-family: PingFang SC,
					PingFang SC;
					font-weight: 400;
					color: #AAAAAA;
				}

				.right {
					font-size: 40rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					color: #FB9D2F;

					image {
						width: 27rpx;
						height: 27rpx;
						margin-left: 10rpx;
					}
				}
			}
		}
	}
</style>